package com.example.mp.modular.api.controller;

import com.example.mp.core.common.JsonUtil;
import com.example.mp.modular.api.model.TestModel;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping(value = "/Hello")
public class Hello {
    @GetMapping(value = "")
    public String index() {
        return "Hello,World";
    }

    @GetMapping(value = "/json")
    @ResponseBody
    public String json(){
        TestModel model = new TestModel();
        model.setId("1");
        model.setName("张三");
        model.setAge(20);
        model.setBirthday(new Date());
        return JsonUtil.toJson(model);
    }
    @GetMapping(value = "/json2")
    @ResponseBody
    public TestModel json2(){
        TestModel model = new TestModel();
        model.setId("1");
        model.setName("张三");
        model.setAge(20);
        model.setBirthday(new Date());
        return model;
    }

    @GetMapping(value = "/test")
    public String test(ModelMap map){
        WxMpUser user = new WxMpUser();
        map.put("user", user);
        map.put("userJson",JsonUtil.toJson(user));
        return "/src/main/resources/static/views/redirect/user.html";
    }
}

